package go_tools

import (
	"bytes"
	"log"
	"os/exec"
	"runtime"
	"strings"
	"syscall"
)

func ExecCmd(cmd string) {
	args := strings.Split(cmd, " ")
	var c *exec.Cmd
	switch runtime.GOOS {
	case "darwin":

	case "windows":
		if len(args) > 1 {
			cmdArgs := args[1:]
			c = exec.Command(args[0], cmdArgs...)
		} else {
			c = exec.Command(args[0])
		}
		c.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
		break
	case "linux":
		c = exec.Command("/bin/sh", "-c", cmd)
		break
	}

	var out bytes.Buffer
	c.Stdout = &out
	c.Run()
	//out,_ := c.Out()
	log.Println(out.String())
}
